package top.yuyufeng.mbuy.service.impl;

import com.github.pagehelper.PageInfo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import top.yuyufeng.mbuy.dao.ProductDao;
import top.yuyufeng.mbuy.dto.PageQuery;
import top.yuyufeng.mbuy.dto.ProductDTO;
import top.yuyufeng.mbuy.entity.Product;
import top.yuyufeng.mbuy.service.IProductService;

@Service
public class ProductServiceImpl implements IProductService {
    @Autowired
    private ProductDao productDao;

    @Override
    public PageInfo<ProductDTO> page(PageQuery pageQuery) {
        PageInfo<ProductDTO> productDTOPageInfo = productDao.page(pageQuery);
        return productDTOPageInfo;
    }

    @Override
    public ProductDTO get(Integer id) {
        Product product = productDao.get(id);
        ProductDTO productDTO = new ProductDTO();
        BeanUtils.copyProperties(product, productDTO);
        return productDTO;
    }
}
